package com.chalk.util;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Date;

public class DateUtil {
    public final static String MAT_ONE = "yyyy-MM-dd";
    public final static String MAT_TWO = "yyyy-MM";
    public final static String MAT_THREE = "MM";
    public final static String MAT_FOUR="yyyy";

    public static String getDateString() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MAT_ONE);
        return simpleDateFormat.format(new Date());

    }

    public static String getMonthString(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MAT_TWO);
        return simpleDateFormat.format(new Date());
    }
    public static String[] getQuarterStrings(){
        String[] arr=new String[3];
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(MAT_THREE);
        SimpleDateFormat year=new SimpleDateFormat(MAT_FOUR);
        String monthString=simpleDateFormat.format(new Date());
        if(monthString.equals("01")||monthString.equals("02") ||monthString.equals("03")){
            arr[0]=year.format(new Date())+"-01";
            arr[1]=year.format(new Date())+"-02";
            arr[2]=year.format(new Date())+"-03";
        }
        if(monthString.equals("04")||monthString.equals("05") ||monthString.equals("06")){
            arr[0]=year.format(new Date())+"-04";
            arr[1]=year.format(new Date())+"-05";
            arr[2]=year.format(new Date())+"-06";
        }
        if(monthString.equals("07")||monthString.equals("08") ||monthString.equals("09")){
            arr[0]=year.format(new Date())+"-07";
            arr[1]=year.format(new Date())+"-08";
            arr[2]=year.format(new Date())+"-09";
        }
        if(monthString.equals("10")||monthString.equals("11") ||monthString.equals("12")){
            arr[0]=year.format(new Date())+"-10";
            arr[1]=year.format(new Date())+"-11";
            arr[2]=year.format(new Date())+"-12";
        }
        return arr;
    }

    public Boolean compareLocalDateTime(LocalDateTime expireDateTime){
        Long nowTime=LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long expireTime=expireDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        if(nowTime<=expireTime){
            return  true;
        }else {
            return false;
        }

    }

    public static Boolean compareDayLocalDateTime(LocalDateTime expireDateTime){
        Long nowTime=LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long expireTime=expireDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long end=expireTime-nowTime;
        if(end>=new Long(0)&&end<=new Long(86400000)){
            return true;
        }

        return false;
    }
    public static void main(String[] args) {
//        System.out.println(getDateString());
//        System.out.println(getMonthString());
//        System.out.println(getQuarterStrings());

        LocalDateTime expireDateTime= LocalDateTime.parse("2020-11-25T14:21:00");
        LocalDateTime nowDateTime=LocalDateTime.parse("2020-11-24T14:21:00");
        Long nowTime=nowDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();
        Long expireTime=expireDateTime.toInstant(ZoneOffset.of("+8")).toEpochMilli();

        System.out.println("------------对比-------"+(expireTime-nowTime));
    }

}
